const path = require('path');
const HomeRouter = require(path.join(__dirname,"HomeRouter"));
const UserRouter = require(path.join(__dirname,"UserRouter"));
const UsertypeRouter = require(path.join(__dirname,"UsertypeRouter"));
const ClassRouter = require(path.join(__dirname,"ClassRouter"));
const GradeRouter = require(path.join(__dirname,"GradeRouter"));
const ProjectRouter = require(path.join(__dirname,"ProjectRouter"));
const SchoolRouter = require(path.join(__dirname,"SchoolRouter"));
const ScoreRouter = require(path.join(__dirname,"ScoreRouter"));
const StudentRouter = require(path.join(__dirname,"StudentRouter"));
const TeacherRouter = require(path.join(__dirname,"TeacherRouter"));
const TermRouter = require(path.join(__dirname,"TermRouter"));
const WeeklyRouter = require(path.join(__dirname,"WeeklyRouter"));



function Router(app)
{
  	//主路由
  	app.get('/',function(req,res){

      	if(req.url == '/home/login' || req.url == '/home/logout')
      	{
          	next();  //跳过
      	}else{
          	if(!req.session.user_name)  //没有登录就跳转到登录界面
          	{
	            //重定向
	            res.redirect(`/home/login`);
          	}
      	}

  	});

	//后台首页路由
	app.use('/home',HomeRouter);

  //班级路由
  app.use('/class',ClassRouter);

	//账号路由
	app.use('/user',UserRouter);

	//账号类型路由
	app.use('/usertype',UsertypeRouter);

  //班级路由
  app.use('/grade',GradeRouter);

  //课程路由
  app.use('/project',ProjectRouter);

  //学校路由
  app.use('/school',SchoolRouter);ScoreRouter

  //成绩路由
  app.use('/score',ScoreRouter);

  //学生路由
  app.use('/student',StudentRouter);

  //教师路由
  app.use('/teacher',TeacherRouter);

  //学期路由
  app.use('/term',TermRouter);

  //周记路由
  app.use('/weekly',WeeklyRouter);
}

module.exports = Router;